function HandlePageTransferIn(gui, operator, now, options) {
  this._gui = gui;
  this._operator = operator;
  this._now = now;
  this._options = options;
  
  this._nowstamp = (options && options.nowstamp) ? options.nowstamp : null;
 
  this._page = 1;
  this._order = 'd.id';
  this._queue = 'DESC';
  this._search = { keyword: '',
                   dateFrom: null,
                   dateTo: null
                 };
  this._lag = 0;
  if (this._nowstamp) {
    this._lag = SimpleDate.toStamp(SimpleDate.create(this._now.year, this._now.month, this._now.date)) - this._nowstamp;
  }

  this._createElements();
};

HandlePageTransferIn.prototype._createElements = function() {
  var _self = this;
  this._popupBox = new PopupBox();
  this._popupBox2 = new PopupBox2();
  
  tr = this._gui.mains.insertRow(-1);
  td = tr.insertCell(-1);
  td.colSpan = 6;
  td.style.backgroundColor = '#fff';
  td.style.borderRight = 'solid 1px #694247';
  td.style.borderBottom = 'solid 1px #694247';
  td.style.borderLeft = 'solid 1px #694247';
  td.appendChild(DOMUtils.getLoadingImage());
  
  this._loadData();
};

HandlePageTransferIn.prototype._loadData = function() {
  this._results = null;
  this._transfers = null;
  this._parameters = null;
  this._retrieveTransfers();
  this._retrieveResults();
};

HandlePageTransferIn.prototype._verifyData = function() {
  if (this._results && this._transfers) {
    this._updateElements();
  }
};

HandlePageTransferIn.prototype._retrieveResults = function(pos) {
  var _self = this;
  var condition = HandleSearchTransferIn.toSql(this._search, this._lag) + ' AND (d.transferto_trackId =\'' + this._operator.trackId + '\')';
  var args = ((condition) ?  '&c=' + encodeURIComponent(condition) : '');
  new RequestUtils()._mysql('ietransfer', args, function(result, params) { _self._results = result;
                                                                           _self._verifyData.call(_self);
                                                                         }, { pos: ((pos) ? pos : null) });
};

HandlePageTransferIn.prototype._retrieveTransfers = function(pos) {
  var _self = this;
  var condition = HandleSearchTransferIn.toSql(this._search, this._lag) + ' AND (d.transferto_trackId =\'' + this._operator.trackId + '\')';
  var args = ((condition) ?  '&c=' + encodeURIComponent(condition) : '') + '&p=' + this._page + '&s=20' + '&o=' + this._order + '&q=' + this._queue;
  new RequestUtils()._mysql('ietransfers', args, function(result, params) { _self._transfers = result.data;
                                                                           _self._parameters = result;
                                                                           _self._verifyData.call(_self);
                                                                         }, { pos: ((pos) ? pos : null) });
};

HandlePageTransferIn.prototype._updateElements = function() {
  var _self = this;
  DlmanageUtils.clear(this._gui.summarize);
  DOMUtils.removeChildElements(this._gui.pagination);
  DOMUtils.removeTableRows(this._gui.mains, 1);

  this._gui.summarize.receipt.appendChild(document.createTextNode('$' + parseFloat(this._results.transfer).toFixed(2)));
  this._gui.summarize.cash.appendChild(document.createTextNode('$' + parseFloat(this._results.cash).toFixed(2)));
  this._gui.summarize.nonCash.appendChild(document.createTextNode('$' + parseFloat(this._results.noncash).toFixed(2)));
  
  //transfer排序
  this._gui.cdate.onclick = function() { _self._order = 'd.createdDate'; _self._queue = (_self._queue && _self._queue == 'ASC') ? 'DESC' : 'ASC'; _self._retrieveTransfers.call(_self); return false;
                                       };
  this._gui.tdate.onclick = function() { _self._order = 'd.transferDate'; _self._queue = (_self._queue && _self._queue == 'ASC') ? 'DESC' : 'ASC'; _self._retrieveTransfers.call(_self); return false;
                                       };
  this._gui.transferFrom.onclick = function() { _self._order = 'd.transferfrom'; _self._queue = (_self._queue && _self._queue == 'ASC') ? 'DESC' : 'ASC'; _self._retrieveTransfers.call(_self); return false;
                                       };

  //payments列表显示
  if (this._transfers.length == 0) {
    tr = this._gui.mains.insertRow(-1);
    td = tr.insertCell(-1);
    td.style.backgroundColor = '#fff';
    td.colSpan = 6;
    td.style.borderRight = 'solid 1px #694247';
    td.style.borderBottom = 'solid 1px #694247';
    td.style.borderLeft = 'solid 1px #694247';
    td.style.height = '24px';
    td.style.textAlign = 'center';
    td.appendChild(document.createTextNode('N/A'));
  }

  for (var i = 0, il = this._transfers.length; i < il; i++) {
    var transfer = this._transfers[i];
    tr = this._gui.mains.insertRow(-1);
    tr.className = (tr.rowIndex % 2 == 0) ? 'roweven' : 'rowodd';
    
    td = tr.insertCell(-1);
    td.style.padding = '0 0 0 5px';
    td.style.textAlign = 'left';
    td.style.borderRight = 'solid 1px #694247';
    td.style.borderBottom = 'solid 1px #694247';
    td.style.borderLeft = 'solid 1px #694247';
    if (transfer.status == -1) {
      td.style.textDecoration = 'line-through';
    }
    td.appendChild(document.createTextNode(SimpleDate.format(transfer.createdDate)));
    
    td = tr.insertCell(-1);
    td.style.padding = '0 0 0 5px';
    td.style.textAlign = 'left';
    td.style.borderRight = 'solid 1px #694247';
    td.style.borderBottom = 'solid 1px #694247';
    if (transfer.status == -1) {
      td.style.textDecoration = 'line-through';
    }
    td.appendChild(document.createTextNode(SimpleDate.format(transfer.transferDate)));
    
    td = tr.insertCell(-1);
    td.style.padding = '0 0 0 5px';
    td.style.textAlign = 'left';
    td.style.borderRight = 'solid 1px #694247';
    td.style.borderBottom = 'solid 1px #694247';
    if (transfer.status == -1) {
      td.style.textDecoration = 'line-through';
    }
    td.appendChild(document.createTextNode(transfer.transferfrom));
    
    td = tr.insertCell(-1);
    td.style.padding = '0 0 0 5px';
    td.style.textAlign = 'left';
    td.style.borderRight = 'solid 1px #694247';
    td.style.borderBottom = 'solid 1px #694247';
    if (transfer.status == -1) {
      td.style.textDecoration = 'line-through';
    }
    td.appendChild(document.createTextNode('$' + transfer.amount));
    
    td = tr.insertCell(-1);
    td.style.padding = '0 0 0 5px';
    td.style.textAlign = 'left';
    td.style.borderRight = 'solid 1px #694247';
    td.style.borderBottom = 'solid 1px #694247';
    if (transfer.status == -1) {
      td.style.textDecoration = 'line-through';
    }
    td.appendChild(document.createTextNode(transfer.method));
    
    td = tr.insertCell(-1);
    td.style.padding = '0 0 0 5px';
    td.style.textAlign = 'left';
    td.style.borderRight = 'solid 1px #694247';
    td.style.borderBottom = 'solid 1px #694247';
    if (transfer.status == -1) {
      td.style.color = '#ff0000';
      if (transfer.cancelledMessage && transfer.cancelledMessage.length > 0) {
        td.appendChild(document.createTextNode('delete: ' + ((transfer.cancelledMessage.length > 40) ? transfer.cancelledMessage.substring(0, 40) + '...' : transfer.cancelledMessage)));
        var a = document.createElement('a');
        a.href = '#';
        a._transfer = transfer;
        a.appendChild(document.createTextNode('All'));
        a.onclick = function() { func1 = function() { _self._popupBox2._close(); };
                                 var pos = DOMUtils.findPos(this);
                                 var div = document.createElement('div');
                                 div.style.verticalAlign = 'top';
                                 div.style.width = '420px';
                                 div.style.color = '#ff0000';
                                 div.style.textAlign = 'left';
                                 div.style.padding = '4px 0 0 5px';
                                 div.style.wordWrap = 'break-word';
                                 div.appendChild(MiscUtils.span('\n' + this._transfer.cancelledMessage));
                                 MiscUtils.dialog(_self._popupBox2, pos, div, func1, null, {t: 'Cancel Reason (' + this._transfer.cancelledOperator + ', ' + SimpleDate.format(this._transfer.cancelledDate) + ')', width: 460, height: 100});
                                 return false;
                               };
        td.appendChild(a);
      } else {
        td.appendChild(document.createTextNode('(none)'));
      }
    } else {
      if (transfer.note && transfer.note.length > 0) {
        td.appendChild(document.createTextNode((transfer.note.length > 40) ? transfer.note.substring(0, 40) + '...' : transfer.note));
        var a = document.createElement('a');
        a.href = '#';
        a._transfer = transfer;
        a.appendChild(document.createTextNode('All'));
        a.onclick = function() { func1 = function() { _self._popupBox._close(); };
                                 var pos = DOMUtils.findPos(this);
                                 var div = document.createElement('div');
                                 div.appendChild(MiscUtils.span('\n' + this._transfer.note));
                                 MiscUtils.dialog(_self._popupBox, pos, div, func1, null);
                                 return false;
                               };
        td.appendChild(a);
      } else {
        td.appendChild(document.createTextNode('(none)'));
      }
    }
  }

  Pagination.makePagedResults(this._gui.pagination, this._parameters.page, this._parameters.total, this._parameters.size, function(page) { _self._page = page, _self._retrieveTransfers.call(_self); }, this, document);
  
  new HandleSearchTransferIn(this._gui.search, this._operator, this._now, { search: this._search, callbackFunc: function(search) { _self._search = search; _self._page = 1; _self._retrieveResults.call(_self); _self._retrieveTransfers.call(_self); } });
};

HandlePageTransferIn.prototype._changeDate = function(label, currentDate, onChangeFunc, showTime) {
  var _self = this;
  this._wContainer = document.createElement('div');
  this._wContainer.style.left = DOMUtils.findPos(label)[0] + 'px';
  this._wContainer.style.top = DOMUtils.findPos(label)[1] + 'px';
  this._popupBox._open(this._wContainer, { pos: DOMUtils.findPos(label) });
  
  var ds = new DateSelect(currentDate, null, { container: this._wContainer, showTime: showTime });
  ds._selectFunc = function(sd) { _self._selectDate.call(_self, sd, label, onChangeFunc, showTime); };
};

HandlePageTransferIn.prototype._selectDate = function(sd, label, onChangeFunc, showTime) {
  
  onChangeFunc(sd);
  this._showDate(sd, label, showTime);
  this._popupBox._close();
};

HandlePageTransferIn.prototype._showDate = function(sd, label, showTime) {
  if (sd) { 
    label.value = SimpleDate.format(sd, showTime);
  } else {
    label.value = '';
  }
};